package cn.iocoder.yudao.framework.handlermapping;

import cn.iocoder.yudao.framework.server.websocket.security.WebSocketUser;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 和当前连接绑定的上下文数据存储类
 *
 * @author 王广帅
 * @version 1.0.0
 * @since 2024/8/28 11:27
 */

public class WsSessionContext {

    private Map<String, Object> session = new ConcurrentHashMap<>();

    private WebSocketUser webSocketUser;

    private String sessionId;

    public void addSessionValue(String key, Object value) {
        this.session.put(key, value);
    }

    public <T> T getSessionValue(String key) {
        if (session.containsKey(key)) {
            return (T) session.get(key);
        }
        return null;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public WebSocketUser getWebSocketUser() {
        return webSocketUser;
    }

    public void setWebSocketUser(WebSocketUser webSocketUser) {
        this.webSocketUser = webSocketUser;
    }
}
